package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.entity.DishFlavor;
import com.sky.mapper.DishFlavorMapper;
import com.sky.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 菜品口味关系表 服务实现类
 *
 * @author alkaid
 * @since 2024-02-20
 */

@Service
public class DishFlavorServiceImpl extends ServiceImpl<DishFlavorMapper, DishFlavor> implements DishFlavorService {

    @Autowired
    private DishFlavorMapper dishFlavorMapper;

    /**
     * 批量插入口味数据
     *
     * @param dishFlavorList
     */
    @Override
    public void createBatch(List<DishFlavor> dishFlavorList) {

        // 逐个插入
        for (DishFlavor dishFlavor : dishFlavorList) {
            dishFlavorMapper.insert(dishFlavor);
        }

    }

    @Override
    public void deleteByDishId(Long dishId) {

        LambdaQueryWrapper<DishFlavor> lambdaQueryWrapper = new LambdaQueryWrapper<DishFlavor>()
                .eq(DishFlavor::getDishId, dishId);

        dishFlavorMapper.delete(lambdaQueryWrapper);

    }

    @Override
    public List<DishFlavor> queryByDishId(Long dishId) {

        LambdaQueryWrapper<DishFlavor> lambdaQueryWrapper = new LambdaQueryWrapper<DishFlavor>()
                .eq(DishFlavor::getDishId, dishId);

        return dishFlavorMapper.selectList(lambdaQueryWrapper);
    }
}
